find_package(PkgConfig)
pkg_check_modules(PC_MATHGL  fribidi)

find_path(MATHGL_INCLUDE_DIRS
    NAMES mgl2/mgl.h
    HINTS ${PC_MATHGL_INCLUDEDIR}
    ${PC_MATHGL_INCLUDE_DIRS}
    #PATH_SUFFIXES mgl2
)

find_library(MATHGL_LIBRARIES
    NAMES mgl
    HINTS ${PC_MATHGL_LIBDIR}
    ${PC_MATHGL_LIBRARY_DIRS}
)

#message("MATHGL_LIBRARIES=${MATHGL_LIBRARIES} MATHGL_INCLUDE_DIRS=${MATHGL_INCLUDE_DIRS} PC_MATHGL_VERSION=${PC_MATHGL_VERSION}")
if(MATHGL_INCLUDE_DIRS AND MATHGL_LIBRARIES)
    set(MATHGL_FOUND TRUE)
    set(MATHGL_LIBRARY ${MATHGL_LIBRARIES})
    set(MATHGL_INCLUDE_DIR ${MATHGL_INCLUDE_DIRS})
    set(MATHGL_VERSION ${PC_MATHGL_VERSION})
endif()

include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(MathGL REQUIRED_VARS MATHGL_INCLUDE_DIRS MATHGL_LIBRARIES 
	FOUND_VAR MATHGL_FOUND VERSION_VAR MATHGL_VERSION)

mark_as_advanced(MATHGL_LIBRARIES MATHGL_LIBRARY MATHGL_INCLUDE_DIRS MATHGL_INCLUDE_DIR MATHGL_FOUND)

